home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / linuxconsole0.4.lcm / etc / hotplug / usb.rc < prev    next >
Encoding:
Text File  |  2004-03-26  |  10.4 KB  |  331 lines

  1. #!/bin/sh
  2. #
  3. # usb.rc    This brings the USB subsystem up and down safely.
  4. #
  5. # $Id: usb.rc,v 1.13 2002/04/01 21:10:53 dbrownell Exp $
  6. #
  7. # Best invoked via /etc/init.d/hotplug or equivalent, with
  8. # writable /tmp, /usr mounted, and syslogging active.
  9. #
  10. # Bus management is basically unrelated to runlevel changes; it
  11. # relates to physical topology, including possibly hotpluggable
  12. # busses (USB, Cardbus) or controllers.  If a bus is physically
  13. # present, it should normally be available.
  14. # USB-dependant systems (iMacs, "legacy free" x86 systems, and so on)
  15. # should statically link USB keyboard support into the kernel (USB core,
  16. # EHCI/OHCI/UHCI/..., hid, input, keybdev; and likely mousedev) so the
  17. # system console can't be removed by accident.
  18.  
  19.  
  20. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  21.  
  22. STATIC_MODULE_LIST=
  23. X11_USBMICE_HACK=false
  24.  
  25. # source function library
  26. if [ -f /etc/init.d/functions ]; then
  27.     . /etc/init.d/functions
  28. elif [ -f /etc/rc.d/init.d/functions ]; then
  29.     . /etc/rc.d/init.d/functions
  30. fi
  31.  
  32.  
  33. # override any of the defaults above?
  34. if [ -f /etc/sysconfig/usb ]; then
  35.     . /etc/sysconfig/usb
  36. fi
  37.  
  38.  
  39. MOUSE_MODULES="mousedev input"
  40.  
  41. # In its currently-recommended configuration, XFree86 3.3.6 always opens
  42. # /dev/input/mice; so mousedev and input must be loaded before X11 starts.
  43. if [ $X11_USBMICE_HACK = true ]; then
  44.     STATIC_MODULE_LIST="$MOUSE_MODULES $STATIC_MODULE_LIST"
  45. fi
  46.  
  47.  
  48. #
  49. # "COLD PLUG" ... recovery from partial USB init that may have happened
  50. # before the OS could really handle hotplug, perhaps because /sbin or
  51. # $HOTPLUG_DIR wasn't available or /tmp wasn't writable.  When/if the
  52. # /sbin/hotplug program is invoked then, hotplug event notifications
  53. # get dropped.  To make up for such "cold boot" errors, we synthesize
  54. # all the hotplug events we expect to have seen already.  They can be
  55. # out of order, and some might be duplicates.
  56. #
  57. usb_boot_events ()
  58. {
  59.     # synthesize hotplug events if we can 
  60.     # we need (non-bash) programs to parse descriptors.
  61.     LISTER=`type -p usbmodules`
  62.     if [ "$LISTER" = "" -o ! -f /proc/bus/usb/devices ]; then
  63.         echo $"** can't synthesize root hub events"
  64.         return
  65.     fi
  66.  
  67.     # make sure the usb agent will run
  68.     ACTION=add
  69.     PRODUCT=0/0/0
  70.     export ACTION PRODUCT
  71.  
  72.     DEVFS=/proc/bus/usb
  73.     DEVICE=
  74.     export DEVFS DEVICE
  75.  
  76.     # these notifications will be handled by usbmodules
  77.     # NOTE: we're not providing a full set of hotplug
  78.     # parameters for USB.  that's why "usbmodules" is a
  79.     # requirement: it reads usbfs to get the others.
  80.     # (it's included in usbutils 0.8 and later)
  81.     for DEVICE in /proc/bus/usb/*/*
  82.     do
  83.         /etc/hotplug/usb.agent
  84.     done
  85. }
  86.  
  87.  
  88. maybe_start_usb ()
  89. {
  90.     local COUNT SYNTHESIZE
  91.     COUNT=0
  92.     SYNTHESIZE=false
  93.  
  94.     # if USB is partially initted (maybe usbcore and hcds were statically
  95.     # linked) then synthesize "cold plug" events since the kernel probably
  96.     # dropped the "hot plug" events.
  97.     # NOTE: if it's not initted at all, no synthesized events will be
  98.     # needed, we'll see real ones.
  99.     if [ -d /proc/bus/usb -a `ls /proc/bus/usb 2>&1 | wc -l` -gt 2 ]; then
  100.     SYNTHESIZE=true
  101.     fi
  102.  
  103.     # if distro hasn't already done part of this ... load core,
  104.     # and mount usbfs before the first hotplug agent fires
  105.     # (so it'll be available to the agents).
  106.     modprobe -q usbcore >/dev/null 2>&1
  107.     if [ -d /proc/bus/usb ]; then
  108.     # if it's not mounted, try to mount it
  109.     if [ ! -f /proc/bus/usb/devices ]; then
  110.         if grep -q "[     ]/proc/bus/usb[     ]" /etc/fstab ; then
  111.         mount /proc/bus/usb
  112.         else
  113.         # NOTE: name is changing to "usbfs" from "usbdevfs"
  114.         mount -t usbdevfs usbdevfs /proc/bus/usb
  115.         fi
  116.     fi
  117.     fi
  118.  
  119.     # Load Host Controller Drivers (HCDs) ... this automatically handles
  120.     # systems with multiple controllers (EHCI, OHCI, UHCI) without needing
  121.     # /proc or tools (lspci -v|grep USB, etc) to do so.  If hotplugging
  122.     # is enabled on this system, initting a root hub will cause hotplug
  123.     # events to fire for every device on the tree at that root.
  124.  
  125.     # FIXME: some of this should be driven by PCI hotplugging, and have
  126.     # the blacklist control which uhci driver gets used (until we
  127.     # finally have just one :)
  128.  
  129.     # "new style" HCDs ... more common code
  130.     modprobe -q ehci-hcd >/dev/null 2>&1
  131.     modprobe -q ohci-hcd >/dev/null 2>&1
  132.     modprobe -q uhci-hcd >/dev/null 2>&1
  133.  
  134.     # "old style" HCDs ... more driver-specific bugs
  135.     modprobe -q usb-ohci >/dev/null 2>&1
  136.     # NOTE: this prefers "usb-uhci"; you may prefer "uhci".
  137.     modprobe -q usb-uhci >/dev/null 2>&1 || modprobe -q uhci >/dev/null 2>&1
  138.     # modprobe -q uhci >/dev/null 2>&1 || modprobe -q usb-uhci >/dev/null 2>&1
  139.  
  140.     # ... add any non-PCI HCDS here.  Examples include the
  141.     # CRIS usb-host, ARM SA-1111, Symlogic 811HS, and so on.
  142.  
  143.     if [ -d /proc/bus/usb ]; then
  144.     # If we see there are no busses, we "failed" and
  145.     # can report so even if we're partially nonmodular.
  146.     COUNT=`ls /proc/bus/usb | wc -l`
  147.     if [ $COUNT -le 2 ]; then
  148.         umount /proc/bus/usb
  149.         rmmod usbcore >/dev/null 2>&1
  150.         return 1
  151.     fi
  152.  
  153.     # if USB is fully modular and yet can clean up,
  154.     # we know init failed without needing usbfs
  155.     elif rmmod usbcore >/dev/null 2>&1; then
  156.     return 1
  157.     fi
  158.  
  159.     # hotplug events didn't fire during booting;
  160.     # cope with devices that enumerated earlier
  161.     # and may not have been fully configured.
  162.     if [ $SYNTHESIZE = true ]; then
  163.         usb_boot_events
  164.     fi
  165.  
  166.     # Some modules are statically loaded, perhaps because they are
  167.     # needed to activate filesystem device nodes.
  168.     for MODULE in $STATIC_MODULE_LIST; do
  169.     modprobe $MODULE
  170.     done
  171.  
  172.     # we did everything we could ...
  173.     return 0
  174. }
  175.  
  176. maybe_stop_usb ()
  177. {
  178.     # call this multiple times if you had to take down components of the
  179.     # USB subsystem by hand; it cleans up whatever can
  180.     # be cleaned up, letting the system quiesce further.
  181.  
  182.     # NOTE:  this list of "all USB modules" is unfortunate, but it seems
  183.     # inevitable until modutils supports the notion of drivers with use
  184.     # counts of zero that shouldn't be removed until after their device
  185.     # gets removed.  Maybe in 2.5 ... of necessity, the list is partial.
  186.  
  187.     # disconnect all controllers we can, and kernel drivers
  188.     # HCDs first, so most drivers reduce their use counts.
  189.     rmmod usb-ohci usb-uhci uhci >/dev/null 2>&1
  190.     rmmod ehci-hcd ohci-hcd uhci-hcd >/dev/null 2>&1
  191.  
  192.     # user mode code may keep usbfs busy for a while yet ...
  193.  
  194.     # OK, usbcore won't actually be removed unless there happen to be
  195.     # no USB drivers loaded, and usbfs isn't mounted.  let's force
  196.     # removal of autocleanable modules before trying to rmmod usbcore
  197.     rmmod -as
  198.  
  199.     # Now let's workaround the fact that some USB modules never increase
  200.     # their module use counts, so that "rmmod -a" won't unload them.
  201.     # (And we can't use "modprobe --autoclean" anyway.)
  202.     rmmod acm              >/dev/null 2>&1
  203.     rmmod audio            >/dev/null 2>&1
  204.     rmmod auerswald        >/dev/null 2>&1
  205.     rmmod belkin_sa        >/dev/null 2>&1
  206.     rmmod bluetooth        >/dev/null 2>&1
  207.     rmmod catc             >/dev/null 2>&1
  208.     rmmod CDCEther         >/dev/null 2>&1
  209.     rmmod cpia_usb         >/dev/null 2>&1
  210.     rmmod cyberjack        >/dev/null 2>&1
  211.     rmmod dabusb           >/dev/null 2>&1
  212.     rmmod dc2xx            >/dev/null 2>&1
  213.     rmmod digi_acceleport  >/dev/null 2>&1
  214.     rmmod dsbr100          >/dev/null 2>&1
  215.     rmmod emi26            >/dev/null 2>&1
  216.     rmmod empeg            >/dev/null 2>&1
  217.     rmmod ftdi_sio         >/dev/null 2>&1
  218.     rmmod hci_usb          >/dev/null 2>&1
  219.     rmmod hid              >/dev/null 2>&1
  220.     rmmod hpusbscsi        >/dev/null 2>&1
  221.     rmmod ibmcam           >/dev/null 2>&1
  222.     rmmod iforce           >/dev/null 2>&1
  223.     rmmod io_edgeport      >/dev/null 2>&1
  224.     rmmod ipaq             >/dev/null 2>&1
  225.     rmmod ir-usb           >/dev/null 2>&1
  226.     rmmod irda-usb         >/dev/null 2>&1
  227.     rmmod kaweth           >/dev/null 2>&1
  228.     rmmod keyspan          >/dev/null 2>&1
  229.     rmmod keyspan_pda      >/dev/null 2>&1
  230.     rmmod kl5kusb105       >/dev/null 2>&1
  231.     rmmod mct_u232         >/dev/null 2>&1
  232.     rmmod mdc800           >/dev/null 2>&1
  233.     rmmod microtek         >/dev/null 2>&1
  234.     rmmod omninet          >/dev/null 2>&1
  235.     rmmod ov511            >/dev/null 2>&1
  236.     rmmod pegasus          >/dev/null 2>&1
  237.     rmmod pl2303           >/dev/null 2>&1
  238.     rmmod printer          >/dev/null 2>&1
  239.     rmmod pwc pwcx         >/dev/null 2>&1
  240.     rmmod rio500           >/dev/null 2>&1
  241.     rmmod rtl8150          >/dev/null 2>&1
  242.     rmmod scanner          >/dev/null 2>&1
  243.     rmmod se401            >/dev/null 2>&1
  244.     rmmod stv680           >/dev/null 2>&1
  245.     rmmod usbkbd           >/dev/null 2>&1
  246.     rmmod usbmouse         >/dev/null 2>&1
  247.     rmmod usbnet           >/dev/null 2>&1
  248.     rmmod usb-storage      >/dev/null 2>&1
  249.     rmmod uss720           >/dev/null 2>&1
  250.     rmmod vicam            >/dev/null 2>&1
  251.     rmmod visor            >/dev/null 2>&1
  252.     rmmod wacom            >/dev/null 2>&1
  253.     rmmod whiteheat        >/dev/null 2>&1
  254.  
  255.     rmmod $STATIC_MODULE_LIST >/dev/null 2>&1
  256.  
  257.     # remove the helper modules that some usb modules need
  258.     rmmod usbserial        >/dev/null 2>&1
  259.     rmmod usbvideo         >/dev/null 2>&1
  260.  
  261.     # ok, hope that user mode drivers/managers closed their fds.
  262.     umount /proc/bus/usb >/dev/null 2>&1
  263.  
  264.     rmmod usbcore >/dev/null 2>&1
  265.  
  266.     # we did everything we could ...
  267.     return 0;
  268. }
  269.  
  270. # See how we were called.
  271. case "$1" in
  272.   start)
  273.     usb_boot_events
  274. #    maybe_start_usb
  275.         ;;
  276.   stop)
  277.     maybe_stop_usb
  278.         ;;
  279.   status)
  280.     echo $"USB Status for kernel: " `uname -srm`
  281.     echo ''
  282.  
  283.     if [ -f /proc/bus/usb/devices ]; then
  284.         COUNT=`ls /proc/bus/usb | wc -l`
  285.         if [ $COUNT -gt 2 ]; then
  286.         COUNT=`expr $COUNT - 2`
  287.         echo $"USB up; bus count is $COUNT"
  288.         grep "^[TPSI]:" /proc/bus/usb/devices
  289.         else
  290.         echo $"usbfs partially up; no busses"
  291.         fi
  292.         echo ''
  293.  
  294.         echo $"USB Drivers Loaded: "
  295.         cat /proc/bus/usb/drivers
  296.     else
  297.         echo $"usbfs is unavailable. "
  298.         if [ -f /proc/modules ] && fgrep -q usbcore /proc/modules; then
  299.         echo $"USB module is loaded. "
  300.         else
  301.         echo $"USB may be statically linked. "
  302.         fi
  303.         echo $"If khubd is running, that shows USB is available."
  304.     fi
  305.     echo ''
  306.  
  307.     if [ -f /proc/sys/kernel/hotplug ]; then
  308.         echo $"khubd/hotplug thread: "
  309.     else
  310.         echo $"khubd thread:"
  311.     fi
  312.     ps -l | head -1
  313.     ps -Al | egrep 'khubd' | grep -v grep
  314.     echo ''
  315.  
  316.     lsmod
  317.     echo ''
  318.  
  319.     # /proc/devices too? "usb", "input", and others ...
  320.  
  321.     ;;
  322.   restart)
  323.     # always invoke by absolute path, else PATH=$PATH:
  324.     $0 stop && $0 start
  325.     ;;
  326.   *)
  327.         echo $"Usage: $0 {start|stop|status|restart}"
  328.         exit 1
  329. esac
  330.